Open
Conversation
Owner
Author
|
NOTE: let Comp = createComponent$(props$ => {
let handler = props$
.pipe(
map(() => () => {
// ... do other stuff
// then call something from current props$
props.current.onClick();
}}
)
return <$button onClick={ handler }/>
});We could do: let Comp = createComponent$(props$ => {
let handler = () => {
// ... do other stuff
// then call something from current props$
props.current.onClick();
};
return <button onClick={ handler }/>
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intro
This feature introduces a reactive components style (like it Recks) with React's hook API available:
Here's an example using react-router useParams hook with data fetching:
And here's a small app, made with
createComponent$: https://stackblitz.com/edit/react-rxjs-elements-components-alphaAPI
react-rxjs-elementsnow additionaly exposes:createComponent$(fn: (props$: Observable<Props>) => JSX | Observable<JSX>)-- create a stream componentuseHook$(fn: () => any)-- use a React hook (or any 3rdparty hook) inside a stream componentuseMount$()anduseUnmount$()-- both return: Observable<void>. Predefined hooks that will emit a void value when the component is mounted and unmountedTry it
This feature is available in the
@nextversion of this library and currently can be tried vianpm i react-rxjs-elements@nextor at stackblitz playground online.Please, share your thoughts and feedback in this thread -- this helps a lot!
Have a good day :)